package edu.hawaii.myisern.model;

import java.util.ArrayList;
import java.util.List;

/**
 * Encapsulates the researcher record.
 * 
 * @author Randy Cox
 * 
 */
public class MyOrganization {

  private Id id;
  private String name;
  private String type;
  private String contact;
  private List<String> affiliatedResearchers;
  private String country;
  private List<String> researchKeywords;
  private String researchDescription;
  private String homePage;

  /**
   * Initialize the data.
   */
  public MyOrganization() {
    initialize();
  }

  /**
   * Initialize and clear record.
   */
  public final void initialize() {
    this.id = new Id();
    this.name = "";
    this.type = "";
    this.contact = "";
    this.affiliatedResearchers = new ArrayList<String>();
    this.country = "";
    this.researchKeywords = new ArrayList<String>();
    this.researchDescription = "";
    this.homePage = "";
  }

  /**
   * @return the id
   */
  public String getId() {
    return id.toString();
  }

  /**
   * Gets name.
   * 
   * @return the name
   */
  public String getName() {
    return name;
  }

  /**
   * Sets name.
   * 
   * @param name the name to set
   */
  public void setName(String name) {
    this.id = new Id(name);
    this.name = name;
  }

  /**
   * Get type.
   * 
   * @return the type
   */
  public String getType() {
    return type;
  }

  /**
   * Set type.
   * 
   * @param type the type to set
   */
  public void setType(String type) {
    this.type = type;
  }

  /**
   * Get contact.
   * 
   * @return the contact
   */
  public String getContact() {
    return contact;
  }

  /**
   * Set contact.
   * 
   * @param contact the contact to set
   */
  public void setContact(String contact) {
    this.contact = contact;
  }

  /**
   * Get country.
   * 
   * @return the country
   */
  public String getCountry() {
    return country;
  }

  /**
   * Set country.
   * 
   * @param country the country to set
   */
  public void setCountry(String country) {
    this.country = country;
  }

  /**
   * Get research description.
   * 
   * @return the researchDescription
   */
  public String getResearchDescription() {
    return researchDescription;
  }

  /**
   * Set research description.
   * 
   * @param researchDescription the researchDescription to set
   */
  public void setResearchDescription(String researchDescription) {
    this.researchDescription = researchDescription;
  }

  /**
   * Get home page.
   * 
   * @return the homePage
   */
  public String getHomePage() {
    return homePage;
  }

  /**
   * Set home page.
   * 
   * @param homePage the homePage to set
   */
  public void setHomePage(String homePage) {
    this.homePage = homePage;
  }

  /**
   * Get a copy of list of affiliated researchers.
   * 
   * @return the copy of affiliatedResearchers
   */
  public List<String> getAffiliatedResearchers() {
    List<String> list = new ArrayList<String>();
    list.addAll(this.affiliatedResearchers);
    return list;
  }

  /**
   * Set copy of list of affiliated researchers.
   * 
   * @param affiliatedResearchers the affiliatedResearchers to set
   */
  public void setAffiliatedResearchers(List<String> affiliatedResearchers) {
    List<String> list = new ArrayList<String>();
    list.addAll(affiliatedResearchers);
    this.affiliatedResearchers = list;
  }

  /**
   * Add on researcher to list.
   * 
   * @param affiliatedResearcher the affiliatedResearcher to add
   */
  public void addAffiliatedResearcher(String affiliatedResearcher) {
    this.affiliatedResearchers.add(affiliatedResearcher);
  }

  /**
   * @return the researchKeywords
   */
  public List<String> getResearchKeywords() {
    List<String> list = new ArrayList<String>();
    list.addAll(this.researchKeywords);
    return list;
  }

  /**
   * @param researchKeywords the researchKeywords to set
   */
  public void setResearchKeywords(List<String> researchKeywords) {
    List<String> list = new ArrayList<String>();
    list.addAll(researchKeywords);
    this.researchKeywords = list;
  }

  /**
   * Add on keyword to list.
   * 
   * @param researchKeyword the research keyword to add
   */
  public void addResearchKeyword(String researchKeyword) {
    this.researchKeywords.add(researchKeyword);
  }

  /**
   * Checks if record has id, name and email populated.
   * 
   * @return true if required fields are populated.
   */
  public Boolean validate() {
    Boolean ok = ((this.id != null) && (this.name != null) && (this.type != null)
        && (this.contact != null) && (this.country != null) && (this.researchDescription != null)
        && (this.homePage != null) && (this.affiliatedResearchers != null) 
        && (this.researchKeywords != null));
    if (ok) {
      ok = ((!this.id.toString().isEmpty()) && (!this.name.isEmpty()));
    }
    return ok;
  }

  /**
   * Creates a string delimited by commas of the record contents.
   * 
   * @return string of record data.
   */
  public String toString() {
    String string = "";
    if (this.validate()) {
      String comma = ", ";
      string = getId() + comma + getName() + comma + getType() + comma + getContact() + comma
          + getCountry() + comma + getResearchDescription() + comma + getHomePage();
    }
    return string;
  }
}
